package priv.dajie.tzzq.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import priv.dajie.tzzq.dao.TradeMapper;
import priv.dajie.tzzq.model.*;
import priv.dajie.tzzq.service.TradeService;
import priv.dajie.tzzq.spider.model.Platform;

import java.math.BigDecimal;
import java.util.List;

/**
 * @ClassName TradeSerciceImpl
 * @Description
 * @Author dajie
 * @Date 2019/10/24 1:24 上午
 * @Version V1.0
 **/

public class TradeSerciceImpl implements TradeService {

    @Autowired
    TradeMapper tradeMapper;

    @Override
    public List<BuyCompareItem> listBuyItem() {
        return tradeMapper.getBuyItems();
    }

    @Override
    public boolean addTrade(BuyGoods buyGoods) {
        return tradeMapper.addTrade(buyGoods);
    }

    @Override
    public TradeStateItems listTradeStateItem(GoodsState goodsState) {
        return tradeMapper.getTradeState(goodsState, null);
    }

    @Override
    public TradeStateItems listTradeStateItem(GoodsState goodsState, Platform platform) {
        return tradeMapper.getTradeState(goodsState, platform);
    }

    @Override
    public boolean updateState(String id, GoodsState goodsState) {
        return updateState(id, goodsState, null, null);
    }

    @Override
    public boolean updateState(String id, GoodsState goodsState, BigDecimal price) {
        return updateState(id, goodsState, price, null);
    }

    @Override
    public boolean updateState(String id, GoodsState goodsState, BigDecimal price, String sellId) {
        TradeStateItem tradeStateItem = new TradeStateItem();
        tradeStateItem.setId(id);
        tradeStateItem.setTradeState(goodsState);
        tradeStateItem.setPrice(price);
        tradeStateItem.setSellId(sellId);
        return tradeMapper.updateTradeState(tradeStateItem);
    }
}
